package com.example.leetcode.trainingcamp.week6.Sunday;

/**
 * 给定一个二叉树，检查它是否是镜像对称的。
 *
 *
 */
public class Test101 {

    private boolean is = true;

    public boolean isSymmetric(TreeNode root) {
        if (root == null) return true;
        isTrue(root.left,root.right);
        return is;
    }

    public void isTrue(TreeNode left,TreeNode right){
        if (left == null && right == null) return;
        if (!is) return;
        if (left != null && right == null) is = false;
        if (right != null && left == null) is = false;
        if (right != null && left != null){
            if (left.val != right.val) is = false;
            isTrue(left.left,right.right);
            isTrue(left.right,right.left);
        }
    }
}
